package com.eralink.unionuhfreader.http;

import static com.eralink.unionuhfreader.MyApplication.cashierDO;

import com.eralink.unionuhfreader.MyApplication;
import com.eralink.unionuhfreader.bean.AppConfirmOrderReqVO;
import com.eralink.unionuhfreader.bean.FormOrder;
import com.eralink.unionuhfreader.bean.RetailProductPageReqVO;
import com.google.gson.Gson;
import com.google.gson.JsonObject;
import com.lzy.okgo.OkGo;
import com.lzy.okgo.model.HttpParams;

import okhttp3.RequestBody;

public class Api {
    private static  final  String baseurl="https://saasapi.hxinsoft.com/yibai";
    private static String adminbaseApi="/admin-api";
    private static String appbaseApi="/app-api";
    private static String getadminapiurl(String uu){
        return  baseurl+adminbaseApi+uu;
    }
    private static String getappUrl(String uu){
        return  baseurl+appbaseApi+uu;
    }

    /**
     *
     * @param username
     * @param password
     * @param callBack
     */
    public static void Login(String username,String password,JsonCallBack callBack){

        Gson gson=new Gson();
        JsonObject jsonObject=new JsonObject();
        jsonObject.addProperty("username",username);
        jsonObject.addProperty("password",password);
        jsonObject.addProperty("clientid","app");
        jsonObject.addProperty("socialCode","");
        jsonObject.addProperty("captchaVerification","11");
        OkGo.post(getadminapiurl("/system/auth/login"))
                .upJson(gson.toJson(jsonObject))
                .execute(callBack);
    }

    public static void refreshToken(JsonCallBack callBack){
        Gson gson=new Gson();
        JsonObject jsonObject=new JsonObject();
        OkGo.post(getadminapiurl("/system/auth/refresh-token?refreshToken="+MyApplication.auth.getRefreshToken()))
                .upJson(gson.toJson(jsonObject))
                .execute(callBack);
    }

    public static void getProduct(RetailProductPageReqVO vo,JsonCallBack callBack){
        Gson gson=new Gson();
        vo.setStoreId(cashierDO.getStoreId());
        OkGo.post(getappUrl("/retail/product/getlist"))
                .upJson(gson.toJson(vo))
                .headers("authorization","Bearer "+ MyApplication.auth.getAccessToken())
                .headers("tenant-id",MyApplication.auth.getTenantId()+"")
                .execute(callBack);
    }
    public static void getCachier(JsonCallBack callBack){
        OkGo.get(getappUrl("/retail/api/getCachierBySn"))
                .params("sn",MyApplication.getSn())
                .execute(callBack);
    }
    public static void getmemberinfo(String mobile,JsonCallBack callBack){
        OkGo.get(getappUrl("/member/user/getUserByMobile"))
                .params("mobile",mobile)
                .headers("tenant-id",MyApplication.auth.getTenantId()+"")
                .execute(callBack);
    }
    public static  void createOrder(FormOrder formOrder,JsonCallBack callBack){
        Gson gson=new Gson();
        OkGo.post(getappUrl("/retail/productOrder/create"))
                .upJson(gson.toJson(formOrder))
                .headers("authorization","Bearer "+ MyApplication.auth.getAccessToken())
                .headers("tenant-id",MyApplication.auth.getTenantId()+"")
                .execute(callBack);
    }
    public static  void confirmOrder(AppConfirmOrderReqVO formOrder, JsonCallBack callBack){
        Gson gson=new Gson();
        OkGo.post(getappUrl("/retail/productOrder/confirmOrder"))
                .upJson(gson.toJson(formOrder))
                .headers("authorization","Bearer "+ MyApplication.auth.getAccessToken())
                .headers("tenant-id",MyApplication.auth.getTenantId()+"")
                .execute(callBack);
    }

    public static  void getorders(int pageNo,int pagesize, JsonCallBack callBack){
        OkGo.get(getadminapiurl("/retail/product-order/page"))
                .params("pageNo",pageNo)
                .params("pageSize",pagesize)
                .headers("authorization","Bearer "+ MyApplication.auth.getAccessToken())
                .headers("tenant-id",MyApplication.auth.getTenantId()+"")
                .execute(callBack);
    }
    public static void getcategory(JsonCallBack callBack){
        OkGo.get(getappUrl("/erp/product-category/select-list"))
                .headers("tenant-id",MyApplication.auth.getTenantId()+"")
                .execute(callBack);
    }

    public static void getproductByEpc(String epc,JsonCallBack callBack){
        OkGo.get(getappUrl("/retail/api/getfushionBYepc"))
                .params("epc",epc)
                .params("storeId",cashierDO.getStoreId())
                .headers("tenant-id",MyApplication.auth.getTenantId()+"")
                .execute(callBack);
    }

    public static void uploadOnecardData(String data,JsonCallBack callBack){
        OkGo.get(getappUrl("/retail/api/saveOneCardData"))
                .params("sn",MyApplication.getSn())
                .params("storeId",cashierDO.getStoreId())
                .params("storeName",cashierDO.getStoreName())
                .params("deviceName",cashierDO.getName())
                .params("recdata",data)
                .headers("tenant-id",MyApplication.auth.getTenantId()+"")
                .execute(callBack);
    }

    public static void checkAppInfo(JsonCallBack callBack){
        OkGo.get(getappUrl("/retail/api/getAppInfo"))
                .params("apptype","casher")
                .headers("tenant-id","1")
                .execute(callBack);
    }
}
